package com.itheima.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
@WebServlet("/testServlet")
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      //设置请求体乱码
        req.setCharacterEncoding("utf-8");
        //设置响应体乱码
        resp.setContentType("text/html;charset=utf-8");

        /*String name = req.getParameter("name");
        System.out.println(name);*/

        BufferedReader reader = req.getReader();
        String s = reader.readLine();
        System.out.println(s);
        resp.getWriter().write("请求成功");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
